//
//  HomeDrawLineTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/29.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "HomeDrawLineTableViewCell.h"
#import "DrawView.h"
#import "CoordinateItem.h"

@interface HomeDrawLineTableViewCell ()
@property (strong, nonatomic) NSMutableArray *dataSource;

@end

@implementation HomeDrawLineTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self buildDataSource];
        [self buildView];
    }
    return self;
}

- (void)buildDataSource
{
    self.dataSource = [NSMutableArray arrayWithCapacity:0];
    
    CoordinateItem *item = [[CoordinateItem alloc] initWithXValue:@"1"
                                                       withYValue:@"3000"
                                                        withColor:[UIColor redColor]];
    [self.dataSource addObject:item];
    
    CoordinateItem *item1 = [[CoordinateItem alloc] initWithXValue:@"5"
                                                        withYValue:@"2467"
                                                         withColor:[UIColor greenColor]];
    [self.dataSource addObject:item1];
    
    CoordinateItem *item2 = [[CoordinateItem alloc] initWithXValue:@"10"
                                                        withYValue:@"2003"
                                                         withColor:[UIColor blueColor]];
    [self.dataSource addObject:item2];
    
    CoordinateItem *item3 = [[CoordinateItem alloc] initWithXValue:@"15"
                                                        withYValue:@"3702"
                                                         withColor:[UIColor grayColor]];
    [self.dataSource addObject:item3];
    
    CoordinateItem *item4 = [[CoordinateItem alloc] initWithXValue:@"20"
                                                        withYValue:@"4392"
                                                         withColor:[UIColor blackColor]];
    [self.dataSource addObject:item4];
    
    CoordinateItem *item5 = [[CoordinateItem alloc] initWithXValue:@"25"
                                                        withYValue:@"1653"
                                                         withColor:[UIColor lightGrayColor]];
    [self.dataSource addObject:item5];
    
    CoordinateItem *item6 = [[CoordinateItem alloc] initWithXValue:@"30日"
                                                        withYValue:@"1234"
                                                         withColor:[UIColor yellowColor]];
    [self.dataSource addObject:item6];
}

- (void)buildView{
    //绘制图形
    DrawView *drawLineChartView = [[DrawView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), kHeightProportion_In_iPhoneTriploid(27), KScreenWidth - kWidthProportion_In_iPhoneTriploid(30), kHeightProportion_In_iPhoneTriploid(215))
                                                   withDataSource:self.dataSource
                                                         withType:LineChartViewType
                                                    withAnimation:YES];
    //只有当视图加载出来(即显示出来的时候才会调用drawRect方法)
//    drawLineChartView.backgroundColor = kRandomColor;
    [self.contentView addSubview:drawLineChartView];
    //
    GLGWLabel * piceLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
    piceLabel.text = @"价格（元）";
    [piceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
        make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(30));
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
    }];
    //
    GLGWLabel * moneyLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
    moneyLabel.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    moneyLabel.textAlignment = NSTextAlignmentCenter;
    moneyLabel.attributedText = [GLGWLabel bllChangeStr:@"11-31 0元/吨" changewithStr:@"0元" changeColoer:[UIColor colorWithHexString:@"#EC5353"] withFont:SYSTEMFONT(12)];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(23));
        make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(27));
        make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(114)));
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(28)));
    }];
    drawLineChartView.Block_DrawBot = ^(GLGWButton * _Nonnull drawBut) {
        CoordinateItem * item = self.dataSource[drawBut.tag - 400];
        moneyLabel.attributedText = [GLGWLabel bllChangeStr:[NSString stringWithFormat:@"11-31 %@元/吨",item.coordinateYValue] changewithStr:[NSString stringWithFormat:@"%@元",item.coordinateYValue] changeColoer:[UIColor colorWithHexString:@"#EC5353"] withFont:SYSTEMFONT(12)];
    };
    //
    GLGWButton * moneyBut = [[GLGWButton alloc] initWithTitle:@"更多行情>" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
//    moneyBut.backgroundColor = kRandomColor;
    [moneyBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(21));
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(75)));
    }];
    //
    GLGWLabel * producetNameLable = [[GLGWLabel alloc] initWithFont:BOLDSYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self.contentView];
    producetNameLable.text = @"三级螺纹钢/HRB400ECR/φ6*12";
    [producetNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(20));
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        make.right.equalTo(moneyBut.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(10));
    }];
    //
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
